﻿using System;
using System.Collections.Generic;
using System.Web;
using He.Web.UI;
using He.Common;

namespace He.Web.tools
{
    /// <summary>
    /// progress_ajax 的摘要说明
    /// </summary>
    public class progress_ajax : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string action = InputUtil.Get("act");
            switch (action)
            {
                case "check_copy":
                    check_copy();
                    break;
                case "remove_cache":
                    remove_cache();
                    break;
            }
        }


        #region 检测拷贝进程===================================
        private void check_copy()
        {
            string threadKey = InputUtil.Get("threadKey");
            string msg = CacheHelper.Get(threadKey) as string;
            EchoJson(1, msg);       
        }
        #endregion

        #region 移除缓存进程===================================
        private void remove_cache()
        {
            string threadKey = InputUtil.Get("threadKey");
            CacheHelper.Remove(threadKey);
        }
        #endregion


        #region 公共
        InputUtil Input = new InputUtil();
        public void EchoJson(int msg, string msgBox)
        {
            EchoJson(msg, msgBox, "");
        }

        public void EchoJson(int msg, string msgBox, string gotoUrl)
        {
            string jsonString = string.Format("{{\"msg\":{0}, \"msgbox\":\"{1}\", \"url\":\"{2}\"}}", msg, msgBox, gotoUrl);
            HttpContext.Current.Response.Write(jsonString);
        }
        #endregion

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}